package marina.Services;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import marina.interfaces.J23SungJukDAO;
import marina.model.J23SungJuk2VO;

public class J23SungJukDAOImpl implements J23SungJukDAO{

	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	private static String URL = "jdbc:oracle:thin:@112.216.253.124:1521:xe";
	private static String insertSQL = ""; 
	private static String readSQL = ""; 
	private static String readOneSQL = ""; 
	private static String updateSQL = ""; 
	private static String deleteSQL = ""; 
	
	public void insertSungJuk(J23SungJuk2VO sj) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		try{
			conn = makeConnection();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			closeConnection(conn, pstmt, null);
		}
	}
	
	//데이터 베이스 접속 생성기
	//makeConnection에서 발생하는 예외는 makeConnection이 직접 처리하지 않고 makeConnection을 호출한 상위 메서드가
	//대신 처리하게 함. 
	//따라서 try-catch-finally 구문을 작성하지 않아도 된다.
	//throws문을 사용하면 예외를 다른 곳으로 전파 가능
	private Connection makeConnection() throws Exception{
		Connection conn = null;
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		return conn;
	}
	
	private void closeConnection(Connection c, PreparedStatement p, ResultSet r){
		if(r != null){
			try{
				r.close();
			} catch(Exception e){
				e.printStackTrace();
			}
		}
		if(p != null){
			try{
				p.close();
			} catch(Exception e){
				e.printStackTrace();
			}
		}
		if(c != null){
			try{
				c.close();
			} catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}
